package com.jf.identity.service.impl;

import com.jf.identity.entity.DeviceRoute;
import com.jf.identity.entity.ExamBaseParam;
import com.jf.identity.entity.ExamBaseParamValidator;
import com.jf.identity.holder.ExamBaseParamHolder;
import com.jf.identity.mongo.DeviceRouteDao;
import com.jf.identity.service.DeviceRouteService;
import com.jf.identity.util.UUIDUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class DeviceRouteServiceImpl implements DeviceRouteService {
    @Resource
    private DeviceRouteDao deviceRouteDao;
    @Resource
    private ExamBaseParamHolder examBaseParamHolder;
    @Resource
    private ExamBaseParamValidator examBaseParamValidator;
    @Override
    public boolean insertDeviceRoute(List<DeviceRoute> deviceRoutes) {
        ExamBaseParam examBaseParam = examBaseParamHolder.getExamBaseParam();
        ExamBaseParam.isBlank(examBaseParam);
        examBaseParamValidator.validate(examBaseParam,ExamBaseParam.EXAM_ID);
        for (DeviceRoute deviceRoute : deviceRoutes) {
            if (deviceRoute == null) {
                continue;
            }
            deviceRoute.setUid(UUIDUtil.generateUUID());
            deviceRoute.setTimestamp(new Date());
            deviceRouteDao.insertDeviceRoute(deviceRoute);
        }
        return true;
    }
}
